<!DOCTYPE html>
<html>

<head>
  <title>Quarkus - Contexts and Dependency Injection</title>
  <script id="adobe_dtm" src="https://www.redhat.com/dtm.js" type="text/javascript"></script>
  <script src="/assets/javascript/highlight.pack.js" type="text/javascript"></script>
  <META HTTP-EQUIV='Content-Security-Policy' CONTENT="default-src 'none'; script-src 'self' 'unsafe-eval' 'sha256-ANpuoVzuSex6VhqpYgsG25OHWVA1I+F6aGU04LoI+5s=' 'sha256-ipy9P/3rZZW06mTLAR0EnXvxSNcnfSDPLDuh3kzbB1w=' js.bizographics.com https://www.redhat.com assets.adobedtm.com jsonip.com https://ajax.googleapis.com https://www.googletagmanager.com https://www.google-analytics.com https://use.fontawesome.com; style-src 'self' https://fonts.googleapis.com https://use.fontawesome.com; img-src 'self' *; media-src 'self' ; frame-src https://www.googletagmanager.com https://www.youtube.com; frame-ancestors 'none'; base-uri 'none'; object-src 'none'; form-action 'none'; font-src 'self' https://use.fontawesome.com https://fonts.gstatic.com;">
  <META HTTP-EQUIV='X-Frame-Options' CONTENT="DENY">
  <META HTTP-EQUIV='X-XSS-Protection' CONTENT="1; mode=block">
  <META HTTP-EQUIV='X-Content-Type-Options' CONTENT="nosniff">
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <meta name="description" content="Quarkus: Supersonic Subatomic Java">
  <meta name="twitter:card" content="summary_large_image">
  <meta name="twitter:site" content="@QuarkusIO"> 
  <meta name="twitter:creator" content="@QuarkusIO">
  <meta property="og:url" content="https://quarkus.io/guides/cdi-reference" />
  <meta property="og:title" content="Quarkus - Contexts and Dependency Injection" />
  <meta property="og:description" content="Quarkus: Supersonic Subatomic Java" />
  <meta property="og:image" content="/assets/images/quarkus_card.png" />
  <link rel="canonical" href="https://quarkus.io/guides/cdi-reference">
  <link rel="shortcut icon" type="image/png" href="/favicon.ico" >
  <link rel="stylesheet" href="https://quarkus.io/guides/stylesheet/config.css" />
  <link rel="stylesheet" href="/assets/css/main.css" />
  <link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.1.0/css/all.css" integrity="sha384-lKuwvrZot6UHsBSfcMvOkWwlCMgc0TaWr+30HWe3a4ltaBwTZhyTEggF5tJv8tbt" crossorigin="anonymous">
  <link rel="alternate" type="application/rss+xml"  href="https://quarkus.io/feed.xml" title="Quarkus">
  <script src="https://quarkus.io/assets/javascript/goan.js" type="text/javascript"></script>
  <script src="https://quarkus.io/assets/javascript/hl.js" type="text/javascript"></script>
</head>

<body class="guides">
  <!-- Google Tag Manager (noscript) -->
  <noscript><iframe src="https://www.googletagmanager.com/ns.html?id=GTM-NJWS5L"
  height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>
  <!-- End Google Tag Manager (noscript) -->

  <div class="nav-wrapper">
  <div class="grid-wrapper">
    <div class="width-12-12">
      <input type="checkbox" id="checkbox" />
      <nav id="main-nav" class="main-nav">
  <div class="container">
    <div class="logo-wrapper">
      
        <a href="/"><img src="/assets/images/quarkus_logo_horizontal_rgb_600px_reverse.png" class="project-logo" title="Quarkus"></a>
      
    </div>
    <label class="nav-toggle" for="checkbox">
      <i class="fa fa-bars"></i>
    </label>
    <div id="menu" class="menu">
      <span>
        <a href="/get-started/" class="">Get Started</a>
      </span>
      <span>
        <a href="/guides/" class="active">Guides</a>
      </span>
      <span>
        <a href="/community/" class="">Community</a>
      </span>
      <span>
        <a href="/support/" class="">Support</a>
      </span>
      <span>
        <a href="/blog/" class="">Blog</a>
      </span>
      <span>
        <a href="https://code.quarkus.io" class="button-cta secondary white">Start Coding</a>
      </span>
    </div>
  </div>
      </nav>
    </div>
  </div>
</div>

  <div class="content">
    <div class="guide">
  <div class="width-12-12">
    <h1 class="text-caps">Quarkus - Contexts and Dependency Injection</h1>
    <div class="hide-mobile toc"><ul class="sectlevel1">
<li><a href="#bean_discovery">1. Bean Discovery</a>
<ul class="sectlevel2">
<li><a href="#how-to-generate-a-jandex-index">1.1. How to Generate a Jandex Index</a></li>
<li><a href="#how-to-exclude-types-and-dependencies-from-discovery">1.2. How To Exclude Types and Dependencies from Discovery</a></li>
</ul>
</li>
<li><a href="#native-executables-and-private-members">2. Native Executables and Private Members</a></li>
<li><a href="#supported_features">3. Supported Features</a></li>
<li><a href="#limitations">4. Limitations</a></li>
<li><a href="#nonstandard_features">5. Non-standard Features</a>
<ul class="sectlevel2">
<li><a href="#eager-instantiation-of-beans">5.1. Eager Instantiation of Beans</a></li>
<li><a href="#request-context-lifecycle">5.2. Request Context Lifecycle</a></li>
<li><a href="#qualified-injected-fields">5.3. Qualified Injected Fields</a></li>
<li><a href="#simplified-constructor-injection">5.4. Simplified Constructor Injection</a></li>
<li><a href="#remove_unused_beans">5.5. Removing Unused Beans</a></li>
<li><a href="#default_beans">5.6. Default Beans</a></li>
<li><a href="#enabling-beans-for-quarkus-build-profile">5.7. Enabling Beans for Quarkus Build Profile</a></li>
<li><a href="#enabling-beans-for-quarkus-build-properties">5.8. Enabling Beans for Quarkus Build Properties</a></li>
<li><a href="#declaring-selected-alternatives">5.9. Declaring Selected Alternatives</a></li>
<li><a href="#simplified-producer-method-declaration">5.10. Simplified Producer Method Declaration</a></li>
<li><a href="#interception-of-static-methods">5.11. Interception of Static Methods</a></li>
<li><a href="#ability-to-handle-final-classes-and-methods">5.12. Ability to handle 'final' classes and methods</a></li>
<li><a href="#container-managed-concurrency">5.13. Container-managed Concurrency</a></li>
</ul>
</li>
<li><a href="#build_time_apis">6. Build Time Extension Points</a>
<ul class="sectlevel2">
<li><a href="#portable_extensions">6.1. Portable Extensions</a></li>
<li><a href="#additional-bean-defining-annotations">6.2. Additional Bean Defining Annotations</a></li>
<li><a href="#resource-annotations">6.3. Resource Annotations</a></li>
<li><a href="#additional_beans">6.4. Additional Beans</a></li>
<li><a href="#synthetic_beans">6.5. Synthetic Beans</a></li>
<li><a href="#annotation-transformations">6.6. Annotation Transformations</a></li>
<li><a href="#additional-interceptor-bindings">6.7. Additional Interceptor Bindings</a></li>
<li><a href="#injection-point-transformation">6.8. Injection Point Transformation</a></li>
<li><a href="#observer-transformation">6.9. Observer Transformation</a></li>
<li><a href="#bean-deployment-validation">6.10. Bean Deployment Validation</a></li>
<li><a href="#custom-contexts">6.11. Custom Contexts</a></li>
<li><a href="#build_metadata">6.12. Available Build Time Metadata</a></li>
</ul>
</li>
<li><a href="#dev-mode">7. Development Mode</a></li>
<li><a href="#arc-configuration-reference">8. ArC Configuration Reference</a></li>
</ul></div>
    <div>
      <div id="preamble">
<div class="sectionbody">
<div class="paragraph">
<p>Quarkus DI solution is based on the <a href="http://docs.jboss.org/cdi/spec/2.0/cdi-spec.html" target="_blank" rel="noopener">Contexts and Dependency Injection for Java 2.0</a> specification.
However, it is not a full CDI implementation verified by the TCK.
Only a subset of the CDI features is implemented - see also <a href="#supported_features">the list of supported features</a> and <a href="#limitations">the list of limitations</a>.</p>
</div>
<div class="admonitionblock tip">
<table>
<tr>
<td class="icon">
<i class="fa icon-tip" title="Tip"></i>
</td>
<td class="content">
If you&#8217;re new to CDI then we recommend you to read the <a href="cdi">Introduction to CDI</a> first.
</td>
</tr>
</table>
</div>
<div class="admonitionblock note">
<table>
<tr>
<td class="icon">
<i class="fa icon-note" title="Note"></i>
</td>
<td class="content">
Most of the existing CDI code should work just fine but there are some small differences which follow from the Quarkus architecture and goals.
</td>
</tr>
</table>
</div>
</div>
</div>
<div class="sect1">
<h2 id="bean_discovery"><a class="anchor" href="#bean_discovery"></a>1. Bean Discovery</h2>
<div class="sectionbody">
<div class="paragraph">
<p>Bean discovery in CDI is a complex process which involves legacy deployment structures and accessibility requirements of the underlying module architecture.
However, Quarkus is using a <strong>simplified bean discovery</strong>.
There is only single bean archive with the <a href="https://docs.jboss.org/cdi/spec/2.0/cdi-spec.html#default_bean_discovery" target="_blank" rel="noopener">bean discovery mode <code>annotated</code></a> and no visibility boundaries.</p>
</div>
<div class="paragraph">
<p>The bean archive is synthesized from:</p>
</div>
<div class="ulist">
<ul>
<li>
<p>the application classes,</p>
</li>
<li>
<p>dependencies that contain a <code>beans.xml</code> descriptor (content is ignored),</p>
</li>
<li>
<p>dependencies that contain a Jandex index - <code>META-INF/jandex.idx</code>,</p>
</li>
<li>
<p>dependencies referenced by <code>quarkus.index-dependency</code> in <code>application.properties</code>,</p>
</li>
<li>
<p>and Quarkus integration code.</p>
</li>
</ul>
</div>
<div class="paragraph">
<p>Bean classes that don&#8217;t have a <a href="http://docs.jboss.org/cdi/spec/2.0/cdi-spec.html#bean_defining_annotations" target="_blank" rel="noopener">bean defining annotation</a> are not discovered.
This behavior is defined by CDI.
But producer methods and fields and observer methods are discovered even if the declaring class is not annotated with a bean defining annotation (this behavior is different to what is defined in CDI).
In fact, the declaring bean classes are considered annotated with <code>@Dependent</code>.</p>
</div>
<div class="admonitionblock note">
<table>
<tr>
<td class="icon">
<i class="fa icon-note" title="Note"></i>
</td>
<td class="content">
Quarkus extensions may declare additional discovery rules. For example, <code>@Scheduled</code> business methods are registered even if the declaring class is not annotated with a bean defining annotation.
</td>
</tr>
</table>
</div>
<div class="sect2">
<h3 id="how-to-generate-a-jandex-index"><a class="anchor" href="#how-to-generate-a-jandex-index"></a>1.1. How to Generate a Jandex Index</h3>
<div class="paragraph">
<p>A dependency with a Jandex index is automatically scanned for beans.
To generate the index just add the following to your <code>pom.xml</code>:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code data-lang="xml" class="language-xml hljs">&lt;build&gt;
  &lt;plugins&gt;
    &lt;plugin&gt;
      &lt;groupId&gt;org.jboss.jandex&lt;/groupId&gt;
      &lt;artifactId&gt;jandex-maven-plugin&lt;/artifactId&gt;
      &lt;version&gt;1.0.7&lt;/version&gt;
      &lt;executions&gt;
        &lt;execution&gt;
          &lt;id&gt;make-index&lt;/id&gt;
          &lt;goals&gt;
            &lt;goal&gt;jandex&lt;/goal&gt;
          &lt;/goals&gt;
        &lt;/execution&gt;
      &lt;/executions&gt;
    &lt;/plugin&gt;
  &lt;/plugins&gt;
&lt;/build&gt;</code></pre>
</div>
</div>
<div class="paragraph">
<p>If you can&#8217;t modify the dependency, you can still index it by adding <code>quarkus.index-dependency</code> entries to your <code>application.properties</code>:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code data-lang="properties" class="language-properties hljs">quarkus.index-dependency.&lt;name&gt;.group-id=
quarkus.index-dependency.&lt;name&gt;.artifact-id=
quarkus.index-dependency.&lt;name&gt;.classifier=(this one is optional)</code></pre>
</div>
</div>
<div class="paragraph">
<p>For example, the following entries ensure that the <code>org.acme:acme-api</code> dependency is indexed:</p>
</div>
</div>
<div class="sect2">
<h3 id="how-to-exclude-types-and-dependencies-from-discovery"><a class="anchor" href="#how-to-exclude-types-and-dependencies-from-discovery"></a>1.2. How To Exclude Types and Dependencies from Discovery</h3>
<div class="paragraph">
<p>It may happen that some beans from third-party libraries do not work correctly in Quarkus.
A typical example is a bean injecting a portable extension.
In such case, it&#8217;s possible to exclude types and dependencies from the bean discovery.
The <code>quarkus.arc.exclude-types</code> property accepts a list of string values that are used to match classes that should be excluded.</p>
</div>
<table class="tableblock frame-all grid-all stretch">
<caption class="title">Table 1. Value Examples</caption>
<colgroup>
<col style="width: 50%;">
<col style="width: 50%;">
</colgroup>
<tbody>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">Value</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Description</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>org.acme.Foo</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Match the fully qualified name of the class</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>org.acme.*</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Match classes with package <code>org.acme</code></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>org.acme.**</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Match classes where the package starts with <code>org.acme</code></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>Bar</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Match the simple name of the class</p></td>
</tr>
</tbody>
</table>
<div class="listingblock">
<div class="title">Example application.properties</div>
<div class="content">
<pre class="highlightjs highlight"><code data-lang="properties" class="language-properties hljs">quarkus.arc.exclude-types=org.acme.Foo,org.acme.*,Bar <i class="conum" data-value="1"></i><b>(1)</b><i class="conum" data-value="2"></i><b>(2)</b><i class="conum" data-value="3"></i><b>(3)</b></code></pre>
</div>
</div>
<div class="colist arabic">
<table>
<tr>
<td><i class="conum" data-value="1"></i><b>1</b></td>
<td>Exclude the type <code>org.acme.Foo</code>.</td>
</tr>
<tr>
<td><i class="conum" data-value="2"></i><b>2</b></td>
<td>Exclude all types from the <code>org.acme</code> package.</td>
</tr>
<tr>
<td><i class="conum" data-value="3"></i><b>3</b></td>
<td>Exclude all types whose simple name is <code>Bar</code></td>
</tr>
</table>
</div>
<div class="paragraph">
<p>It is also possible to exclude a dependency artifact that would be otherwise scanned for beans.
For example, because it contains a <code>beans.xml</code> descriptor.</p>
</div>
<div class="listingblock">
<div class="title">Example application.properties</div>
<div class="content">
<pre class="highlightjs highlight"><code data-lang="properties" class="language-properties hljs">quarkus.arc.exclude-dependency.acme.group-id=org.acme <i class="conum" data-value="1"></i><b>(1)</b>
quarkus.arc.exclude-dependency.acme.artifact-id=acme-services <i class="conum" data-value="2"></i><b>(2)</b></code></pre>
</div>
</div>
<div class="colist arabic">
<table>
<tr>
<td><i class="conum" data-value="1"></i><b>1</b></td>
<td>Value is a group id for a dependency identified by name <code>acme</code>.</td>
</tr>
<tr>
<td><i class="conum" data-value="2"></i><b>2</b></td>
<td>Value is an artifact id for a dependency identified by name <code>acme</code>.</td>
</tr>
</table>
</div>
</div>
</div>
</div>
<div class="sect1">
<h2 id="native-executables-and-private-members"><a class="anchor" href="#native-executables-and-private-members"></a>2. Native Executables and Private Members</h2>
<div class="sectionbody">
<div class="paragraph">
<p>Quarkus is using GraalVM to build a native executable.
One of the limitations of GraalVM is the usage of <a href="https://github.com/oracle/graal/blob/master/substratevm/LIMITATIONS.md#user-content-reflection" target="_blank" rel="noopener">Reflection</a>.
Reflective operations are supported but all relevant members must be registered for reflection explicitly.
Those registrations result in a bigger native executable.</p>
</div>
<div class="paragraph">
<p>And if Quarkus DI needs to access a private member it <strong>has to use reflection</strong>.
That&#8217;s why Quarkus users are encouraged <em>not to use private members</em> in their beans.
This involves injection fields, constructors and initializers, observer methods, producer methods and fields, disposers and interceptor methods.</p>
</div>
<div class="paragraph">
<p>How to avoid using private members?
You can use package-private modifiers:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code data-lang="java" class="language-java hljs">@ApplicationScoped
public class CounterBean {

    @Inject
    CounterService counterService; <i class="conum" data-value="1"></i><b>(1)</b>

    void onMessage(@Observes Event msg) { <i class="conum" data-value="2"></i><b>(2)</b>
    }
}</code></pre>
</div>
</div>
<div class="colist arabic">
<table>
<tr>
<td><i class="conum" data-value="1"></i><b>1</b></td>
<td>A package-private injection field.</td>
</tr>
<tr>
<td><i class="conum" data-value="2"></i><b>2</b></td>
<td>A package-private observer method.</td>
</tr>
</table>
</div>
<div class="paragraph">
<p>Or constructor injection:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code data-lang="java" class="language-java hljs">@ApplicationScoped
public class CounterBean {

    private CounterService service;

    CounterBean(CounterService service) { <i class="conum" data-value="1"></i><b>(1)</b>
      this.service = service;
    }
}</code></pre>
</div>
</div>
<div class="colist arabic">
<table>
<tr>
<td><i class="conum" data-value="1"></i><b>1</b></td>
<td>A package-private constructor injection. <code>@Inject</code> is optional in this particular case.</td>
</tr>
</table>
</div>
</div>
</div>
<div class="sect1">
<h2 id="supported_features"><a class="anchor" href="#supported_features"></a>3. Supported Features</h2>
<div class="sectionbody">
<div class="ulist">
<ul>
<li>
<p>Programming model</p>
<div class="ulist">
<ul>
<li>
<p>Managed beans implemented by a Java class</p>
<div class="ulist">
<ul>
<li>
<p><code>@PostConstruct</code> and <code>@PreDestroy</code> lifecycle callbacks</p>
</li>
</ul>
</div>
</li>
<li>
<p>Producer methods and fields, disposers</p>
</li>
<li>
<p>Qualifiers</p>
</li>
<li>
<p>Alternatives</p>
</li>
<li>
<p>Stereotypes</p>
</li>
</ul>
</div>
</li>
<li>
<p>Dependency injection and lookup</p>
<div class="ulist">
<ul>
<li>
<p>Field, constructor and initializer/setter injection</p>
</li>
<li>
<p>Type-safe resolution</p>
</li>
<li>
<p>Programmatic lookup via <code>javax.enterprise.inject.Instance</code></p>
</li>
<li>
<p>Client proxies</p>
</li>
<li>
<p>Injection point metadata</p>
</li>
</ul>
</div>
</li>
<li>
<p>Scopes and contexts</p>
<div class="ulist">
<ul>
<li>
<p><code>@Dependent</code>, <code>@ApplicationScoped</code>, <code>@Singleton</code>, <code>@RequestScoped</code> and <code>@SessionScoped</code></p>
</li>
<li>
<p>Custom scopes and contexts</p>
</li>
</ul>
</div>
</li>
<li>
<p>Interceptors</p>
<div class="ulist">
<ul>
<li>
<p>Business method interceptors: <code>@AroundInvoke</code></p>
</li>
<li>
<p>Interceptors for lifecycle event callbacks: <code>@PostConstruct</code>, <code>@PreDestroy</code>, <code>@AroundConstruct</code></p>
</li>
</ul>
</div>
</li>
<li>
<p>Events and observer methods, including asynchronous events and transactional observer methods</p>
</li>
</ul>
</div>
</div>
</div>
<div class="sect1">
<h2 id="limitations"><a class="anchor" href="#limitations"></a>4. Limitations</h2>
<div class="sectionbody">
<div class="ulist">
<ul>
<li>
<p><code>@ConversationScoped</code> is not supported</p>
</li>
<li>
<p>Decorators are not supported</p>
</li>
<li>
<p>Portable Extensions are not supported</p>
</li>
<li>
<p><code>BeanManager</code> - only the following methods are implemented: <code>getBeans()</code>, <code>createCreationalContext()</code>, <code>getReference()</code>, <code>getInjectableReference()</code> , <code>resolve()</code>, <code>getContext()</code>, <code>fireEvent()</code>, <code>getEvent()</code> and <code>createInstance()</code></p>
</li>
<li>
<p>Specialization is not supported</p>
</li>
<li>
<p><code>beans.xml</code> descriptor content is ignored</p>
</li>
<li>
<p>Passivation and passivating scopes are not supported</p>
</li>
<li>
<p>Interceptor methods on superclasses are not implemented yet</p>
</li>
<li>
<p><code>@Interceptors</code> is not supported</p>
</li>
</ul>
</div>
</div>
</div>
<div class="sect1">
<h2 id="nonstandard_features"><a class="anchor" href="#nonstandard_features"></a>5. Non-standard Features</h2>
<div class="sectionbody">
<div class="sect2">
<h3 id="eager-instantiation-of-beans"><a class="anchor" href="#eager-instantiation-of-beans"></a>5.1. Eager Instantiation of Beans</h3>
<div class="sect3">
<h4 id="lazy_by_default"><a class="anchor" href="#lazy_by_default"></a>5.1.1. Lazy By Default</h4>
<div class="paragraph">
<p>By default, CDI beans are created lazily, when needed.
What exactly "needed" means depends on the scope of a bean.</p>
</div>
<div class="ulist">
<ul>
<li>
<p>A <strong>normal scoped bean</strong> (<code>@ApplicationScoped</code>, <code>@RequestScoped</code>, etc.) is needed when a method is invoked upon an injected instance (contextual reference per the specification).</p>
<div class="paragraph">
<p>In other words, injecting a normal scoped bean will not suffice because a <em>client proxy</em> is injected instead of a contextual instance of the bean.</p>
</div>
</li>
<li>
<p>A <strong>bean with a pseudo-scope</strong> (<code>@Dependent</code> and <code>@Singleton</code> ) is created when injected.</p>
</li>
</ul>
</div>
<div class="listingblock">
<div class="title">Lazy Instantiation Example</div>
<div class="content">
<pre class="highlightjs highlight"><code data-lang="java" class="language-java hljs">@Singleton // =&gt; pseudo-scope
class AmazingService {
  String ping() {
    return "amazing";
  }
}

@ApplicationScoped // =&gt; normal scope
class CoolService {
  String ping() {
    return "cool";
  }
}

@Path("/ping")
public class PingResource {

  @Inject
  AmazingService s1; <i class="conum" data-value="1"></i><b>(1)</b>

  @Inject
  CoolService s2; <i class="conum" data-value="2"></i><b>(2)</b>

  @GET
  public String ping() {
    return s1.ping() + s2.ping(); <i class="conum" data-value="3"></i><b>(3)</b>
  }
}</code></pre>
</div>
</div>
<div class="colist arabic">
<table>
<tr>
<td><i class="conum" data-value="1"></i><b>1</b></td>
<td>Injection triggers the instantiation of <code>AmazingService</code>.</td>
</tr>
<tr>
<td><i class="conum" data-value="2"></i><b>2</b></td>
<td>Injection itself does not result in the instantiation of <code>CoolService</code>. A client proxy is injected.</td>
</tr>
<tr>
<td><i class="conum" data-value="3"></i><b>3</b></td>
<td>The first invocation upon the injected proxy triggers the instantiation of <code>CoolService</code>.</td>
</tr>
</table>
</div>
</div>
<div class="sect3">
<h4 id="startup-event"><a class="anchor" href="#startup-event"></a>5.1.2. Startup Event</h4>
<div class="paragraph">
<p>However, if you really need to instantiate a bean eagerly you can:</p>
</div>
<div class="ulist">
<ul>
<li>
<p>Declare an observer of the <code>StartupEvent</code> - the scope of the bean does not matter in this case:</p>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code data-lang="java" class="language-java hljs">@ApplicationScoped
class CoolService {
  void startup(@Observes StartupEvent event) { <i class="conum" data-value="1"></i><b>(1)</b>
  }
}</code></pre>
</div>
</div>
<div class="colist arabic">
<table>
<tr>
<td><i class="conum" data-value="1"></i><b>1</b></td>
<td>A <code>CoolService</code> is created during startup to service the observer method invocation.</td>
</tr>
</table>
</div>
</li>
<li>
<p>Use the bean in an observer of the <code>StartupEvent</code> - normal scoped beans must be used as described in <a href="#lazy_by_default">Lazy By Default</a>:</p>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code data-lang="java" class="language-java hljs">@Dependent
class MyBeanStarter {

  void startup(@Observes StartupEvent event, AmazingService amazing, CoolService cool) { <i class="conum" data-value="1"></i><b>(1)</b>
    cool.toString(); <i class="conum" data-value="2"></i><b>(2)</b>
  }
}</code></pre>
</div>
</div>
<div class="colist arabic">
<table>
<tr>
<td><i class="conum" data-value="1"></i><b>1</b></td>
<td>The <code>AmazingService</code> is created during injection.</td>
</tr>
<tr>
<td><i class="conum" data-value="2"></i><b>2</b></td>
<td>The <code>CoolService</code> is a normal scoped bean so we have to invoke a method upon the injected proxy to force the instantiation.</td>
</tr>
</table>
</div>
</li>
<li>
<p>Annotate the bean with <code>@io.quarkus.runtime.Startup</code> as described in <a href="lifecycle#startup_annotation">Startup annotation</a>:</p>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code data-lang="java" class="language-java hljs">@Startup <i class="conum" data-value="1"></i><b>(1)</b>
@ApplicationScoped
public class EagerAppBean {

   private final String name;

   EagerAppBean(NameGenerator generator) { <i class="conum" data-value="2"></i><b>(2)</b>
     this.name = generator.createName();
   }
}</code></pre>
</div>
</div>
<div class="olist arabic">
<ol class="arabic">
<li>
<p>For each bean annotated with <code>@Startup</code> a synthetic observer of <code>StartupEvent</code> is generated. The default priority is used.</p>
</li>
<li>
<p>The bean constructor is called when the application starts and the resulting contextual instance is stored in the application context.</p>
</li>
</ol>
</div>
</li>
</ul>
</div>
<div class="admonitionblock note">
<table>
<tr>
<td class="icon">
<i class="fa icon-note" title="Note"></i>
</td>
<td class="content">
Quarkus users are encouraged to always prefer the <code>@Observes StartupEvent</code> to <code>@Initialized(ApplicationScoped.class)</code> as explained in the <a href="lifecycle">Application Initialization and Termination</a> guide.
</td>
</tr>
</table>
</div>
</div>
</div>
<div class="sect2">
<h3 id="request-context-lifecycle"><a class="anchor" href="#request-context-lifecycle"></a>5.2. Request Context Lifecycle</h3>
<div class="paragraph">
<p>The request context is also active:</p>
</div>
<div class="ulist">
<ul>
<li>
<p>during notification of a synchronous observer method.</p>
</li>
</ul>
</div>
<div class="paragraph">
<p>The request context is destroyed:</p>
</div>
<div class="ulist">
<ul>
<li>
<p>after the observer notification completes for an event, if it was not already active when the notification started.</p>
</li>
</ul>
</div>
<div class="admonitionblock note">
<table>
<tr>
<td class="icon">
<i class="fa icon-note" title="Note"></i>
</td>
<td class="content">
An event with qualifier <code>@Initialized(RequestScoped.class)</code> is fired when the request context is initialized for an observer notification. Moreover, the events with qualifiers <code>@BeforeDestroyed(RequestScoped.class)</code> and <code>@Destroyed(RequestScoped.class)</code> are fired when the request context is destroyed.
</td>
</tr>
</table>
</div>
</div>
<div class="sect2">
<h3 id="qualified-injected-fields"><a class="anchor" href="#qualified-injected-fields"></a>5.3. Qualified Injected Fields</h3>
<div class="paragraph">
<p>In CDI, if you declare a field injection point you need to use <code>@Inject</code> and optionally a set of qualifiers.</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code data-lang="java" class="language-java hljs">  @Inject
  @ConfigProperty(name = "cool")
  String coolProperty;</code></pre>
</div>
</div>
<div class="paragraph">
<p>In Quarkus, you can skip the <code>@Inject</code> annotation completely if the injected field declares at least one qualifier.</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code data-lang="java" class="language-java hljs">  @ConfigProperty(name = "cool")
  String coolProperty;</code></pre>
</div>
</div>
<div class="admonitionblock note">
<table>
<tr>
<td class="icon">
<i class="fa icon-note" title="Note"></i>
</td>
<td class="content">
With the notable exception of one special case discussed below, <code>@Inject</code> is still required for constructor and method injection.
</td>
</tr>
</table>
</div>
</div>
<div class="sect2">
<h3 id="simplified-constructor-injection"><a class="anchor" href="#simplified-constructor-injection"></a>5.4. Simplified Constructor Injection</h3>
<div class="paragraph">
<p>In CDI, a normal scoped bean must always declare a no-args constructor (this constructor is normally generated by the compiler unless you declare any other constructor).
However, this requirement complicates constructor injection - you need to provide a dummy no-args constructor to make things work in CDI.</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code data-lang="java" class="language-java hljs">@ApplicationScoped
public class MyCoolService {

  private SimpleProcessor processor;

  MyCoolService() { // dummy constructor needed
  }

  @Inject // constructor injection
  MyCoolService(SimpleProcessor processor) {
    this.processor = processor;
  }
}</code></pre>
</div>
</div>
<div class="paragraph">
<p>There is no need to declare dummy constructors for normal scoped bean in Quarkus - they are generated automatically.
Also if there&#8217;s only one constructor there is no need for <code>@Inject</code>.</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code data-lang="java" class="language-java hljs">@ApplicationScoped
public class MyCoolService {

  private SimpleProcessor processor;

  MyCoolService(SimpleProcessor processor) {
    this.processor = processor;
  }
}</code></pre>
</div>
</div>
<div class="admonitionblock note">
<table>
<tr>
<td class="icon">
<i class="fa icon-note" title="Note"></i>
</td>
<td class="content">
We don&#8217;t generate a no-args constructor automatically if a bean class extends a class that does not declare a no-args constructor.
</td>
</tr>
</table>
</div>
</div>
<div class="sect2">
<h3 id="remove_unused_beans"><a class="anchor" href="#remove_unused_beans"></a>5.5. Removing Unused Beans</h3>
<div class="paragraph">
<p>The container attempts to remove all unused beans during build by default.
This optimization can be disabled by setting <code>quarkus.arc.remove-unused-beans</code> to <code>none</code> or <code>false</code>.</p>
</div>
<div class="paragraph">
<p>An unused bean:</p>
</div>
<div class="ulist">
<ul>
<li>
<p>is not a built-in bean or an interceptor,</p>
</li>
<li>
<p>is not eligible for injection to any injection point,</p>
</li>
<li>
<p>is not excluded by any extension,</p>
</li>
<li>
<p>does not have a name,</p>
</li>
<li>
<p>does not declare an observer,</p>
</li>
<li>
<p>does not declare any producer which is eligible for injection to any injection point,</p>
</li>
<li>
<p>is not directly eligible for injection into any <code>javax.enterprise.inject.Instance</code> or <code>javax.inject.Provider</code> injection point</p>
</li>
</ul>
</div>
<div class="paragraph">
<p>This optimization applies to all forms of bean declarations: bean class, producer method, producer field.</p>
</div>
<div class="paragraph">
<p>Users can instruct the container to not remove any of their specific beans (even if they satisfy all the rules specified above) by annotating them with <code>io.quarkus.arc.Unremovable</code>.
This annotation can be placed on the types, producer methods, and producer fields.</p>
</div>
<div class="paragraph">
<p>Since this is not always possible, there is an option to achieve the same via <code>application.properties</code>.
The <code>quarkus.arc.unremovable-types</code> property accepts a list of string values that are used to match beans based on their name or package.</p>
</div>
<table class="tableblock frame-all grid-all stretch">
<caption class="title">Table 2. Value Examples</caption>
<colgroup>
<col style="width: 50%;">
<col style="width: 50%;">
</colgroup>
<tbody>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">Value</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Description</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>org.acme.Foo</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Match the fully qualified name of the bean class</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>org.acme.*</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Match beans where the package of the bean class is <code>org.acme</code></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>org.acme.**</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Match beans where the package of the bean class starts with <code>org.acme</code></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>Bar</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Match the simple name of the bean class</p></td>
</tr>
</tbody>
</table>
<div class="listingblock">
<div class="title">Example application.properties</div>
<div class="content">
<pre class="highlightjs highlight"><code data-lang="properties" class="language-properties hljs">quarkus.arc.unremovable-types=org.acme.Foo,org.acme.*,Bar</code></pre>
</div>
</div>
<div class="paragraph">
<p>Furthermore, extensions can eliminate possible false positives by producing <code>UnremovableBeanBuildItem</code>.</p>
</div>
<div class="paragraph">
<p>Finally, Quarkus provides a middle ground for the bean removal optimization where application beans are never removed whether or not they are unused,
while the optimization proceeds normally for non application classes. To use this mode, set <code>quarkus.arc.remove-unused-beans</code> to <code>fwk</code> or <code>framework</code>.</p>
</div>
<div class="paragraph">
<p>When using the dev mode (running <code>./mvnw clean compile quarkus:dev</code>), you can see more information about which beans are being removed
by enabling additional logging via the following line in your <code>application.properties</code>.</p>
</div>
<div class="listingblock">
<div class="content">
<pre>quarkus.log.category."io.quarkus.arc.processor".level=DEBUG</pre>
</div>
</div>
</div>
<div class="sect2">
<h3 id="default_beans"><a class="anchor" href="#default_beans"></a>5.6. Default Beans</h3>
<div class="paragraph">
<p>Quarkus adds a capability that CDI currently does not support which is to conditionally declare a bean if no other bean with equal types and qualifiers was declared by any available means (bean class, producer, synthetic bean, &#8230;&#8203;)
This is done using the <code>@io.quarkus.arc.DefaultBean</code> annotation and is best explained with an example.</p>
</div>
<div class="paragraph">
<p>Say there is a Quarkus extension that among other things declares a few CDI beans like the following code does:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code data-lang="java" class="language-java hljs">@Dependent
public class TracerConfiguration {

    @Produces
    public Tracer tracer(Reporter reporter, Configuration configuration) {
        return new Tracer(reporter, configuration);
    }

    @Produces
    @DefaultBean
    public Configuration configuration() {
        // create a Configuration
    }

    @Produces
    @DefaultBean
    public Reporter reporter(){
        // create a Reporter
    }
}</code></pre>
</div>
</div>
<div class="paragraph">
<p>The idea is that the extension auto-configures things for the user, eliminating a lot of boilerplate - we can just <code>@Inject</code> a <code>Tracer</code> wherever it is needed.
Now imagine that in our application we would like to utilize the configured <code>Tracer</code>, but we need to customize it a little, for example by providing a custom <code>Reporter</code>.
The only thing that would be needed in our application would be something like the following:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code data-lang="java" class="language-java hljs">@Dependent
public class CustomTracerConfiguration {

    @Produces
    public Reporter reporter(){
        // create a custom Reporter
    }
}</code></pre>
</div>
</div>
<div class="paragraph">
<p><code>@DefaultBean</code> allows extensions (or any other code for that matter) to provide defaults while backing off if beans of that type are supplied in any
way Quarkus supports.</p>
</div>
</div>
<div class="sect2">
<h3 id="enabling-beans-for-quarkus-build-profile"><a class="anchor" href="#enabling-beans-for-quarkus-build-profile"></a>5.7. Enabling Beans for Quarkus Build Profile</h3>
<div class="paragraph">
<p>Quarkus adds a capability that CDI currently does not support which is to conditionally enable a bean when a Quarkus build time profile is enabled,
via the <code>@io.quarkus.arc.profile.IfBuildProfile</code> and <code>@io.quarkus.arc.profile.UnlessBuildProfile</code> annotations.
When used in conjunction with <code>@io.quarkus.arc.DefaultBean</code>, these annotations allow for the creation of different bean configurations for different build profiles.</p>
</div>
<div class="paragraph">
<p>Imagine for instance that an application contains a bean named <code>Tracer</code>, which needs to be do nothing when in tests or dev-mode, but work in its normal capacity for the production artifact.
An elegant way to create such beans is the following:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code data-lang="java" class="language-java hljs">@Dependent
public class TracerConfiguration {

    @Produces
    @IfBuildProfile("prod")
    public Tracer realTracer(Reporter reporter, Configuration configuration) {
        return new RealTracer(reporter, configuration);
    }

    @Produces
    @DefaultBean
    public Tracer noopTracer() {
        return new NoopTracer();
    }
}</code></pre>
</div>
</div>
<div class="paragraph">
<p>If instead, it is required that the <code>Tracer</code> bean also work in dev-mode and only default to doing nothing for tests, then <code>@UnlessBuildProfile</code> would be ideal. The code would look like:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code data-lang="java" class="language-java hljs">@Dependent
public class TracerConfiguration {

    @Produces
    @DefaultBean
    public Tracer realTracer(Reporter reporter, Configuration configuration) {
        return new RealTracer(reporter, configuration);
    }

    @Produces
    @UnlessBuildProfile("prod") // this will be enabled for both test and dev build time profiles
    public Tracer noopTracer() {
        return new NoopTracer();
    }
}</code></pre>
</div>
</div>
<div class="admonitionblock note">
<table>
<tr>
<td class="icon">
<i class="fa icon-note" title="Note"></i>
</td>
<td class="content">
The runtime profile has absolutely no effect on the bean resolution using <code>@IfBuildProfile</code> and <code>@UnlessBuildProfile</code>.
</td>
</tr>
</table>
</div>
</div>
<div class="sect2">
<h3 id="enabling-beans-for-quarkus-build-properties"><a class="anchor" href="#enabling-beans-for-quarkus-build-properties"></a>5.8. Enabling Beans for Quarkus Build Properties</h3>
<div class="paragraph">
<p>Quarkus adds a capability that CDI currently does not support which is to conditionally enable a bean when a Quarkus build time property has a specific value,
via the <code>@io.quarkus.arc.properties.IfBuildProperty</code> annotation.
When used in conjunction with <code>@io.quarkus.arc.DefaultBean</code>, this annotation allow for the creation of different bean configurations for different build properties.</p>
</div>
<div class="paragraph">
<p>The scenario we mentioned above with <code>Tracer</code> could also be implemented in the following way:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code data-lang="java" class="language-java hljs">@Dependent
public class TracerConfiguration {

    @Produces
    @IfBuildProperty(name = "some.tracer.enabled", stringValue = "true")
    public Tracer realTracer(Reporter reporter, Configuration configuration) {
        return new RealTracer(reporter, configuration);
    }

    @Produces
    @DefaultBean
    public Tracer noopTracer() {
        return new NoopTracer();
    }
}</code></pre>
</div>
</div>
<div class="admonitionblock note">
<table>
<tr>
<td class="icon">
<i class="fa icon-note" title="Note"></i>
</td>
<td class="content">
Properties set at runtime have absolutely no effect on the bean resolution using <code>@IfBuildProperty</code>.
</td>
</tr>
</table>
</div>
</div>
<div class="sect2">
<h3 id="declaring-selected-alternatives"><a class="anchor" href="#declaring-selected-alternatives"></a>5.9. Declaring Selected Alternatives</h3>
<div class="paragraph">
<p>In CDI, an alternative bean may be selected either globally for an application by means of <code>@Priority</code>, or for a bean archive using a <code>beans.xml</code> descriptor.
Quarkus has a simplified bean discovery and the content of <code>beans.xml</code> is ignored.</p>
</div>
<div class="paragraph">
<p>The disadvantage of <code>@Priority</code> is that it has <code>@Target({ TYPE, PARAMETER })</code> and so it cannot be used for producer methods and fields.
To address this problem and to simplify the code Quarkus provides the <code>io.quarkus.arc.AlternativePriority</code> annotation.
It&#8217;s basically a shortcut for <code>@Alternative</code> plus <code>@Priority</code>.
Additionally, it can be used for producers.</p>
</div>
<div class="paragraph">
<p>However, it is also possible to select alternatives for an application using the unified configuration.
The <code>quarkus.arc.selected-alternatives</code> property accepts a list of string values that are used to match alternative beans.
If any value matches then the priority of <code>Integer#MAX_VALUE</code> is used for the relevant bean.
The priority declared via <code>@Priority</code> or <code>@AlternativePriority</code> is overridden.</p>
</div>
<table class="tableblock frame-all grid-all stretch">
<caption class="title">Table 3. Value Examples</caption>
<colgroup>
<col style="width: 50%;">
<col style="width: 50%;">
</colgroup>
<tbody>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">Value</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Description</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>org.acme.Foo</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Match the fully qualified name of the bean class or the bean class of the bean that declares the producer</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>org.acme.*</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Match beans where the package of the bean class is <code>org.acme</code></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>org.acme.**</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Match beans where the package of the bean class starts with <code>org.acme</code></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>Bar</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Match the simple name of the bean class or the bean class of the bean that declares the producer</p></td>
</tr>
</tbody>
</table>
<div class="listingblock">
<div class="title">Example application.properties</div>
<div class="content">
<pre class="highlightjs highlight"><code data-lang="properties" class="language-properties hljs">quarkus.arc.selected-alternatives=org.acme.Foo,org.acme.*,Bar</code></pre>
</div>
</div>
</div>
<div class="sect2">
<h3 id="simplified-producer-method-declaration"><a class="anchor" href="#simplified-producer-method-declaration"></a>5.10. Simplified Producer Method Declaration</h3>
<div class="paragraph">
<p>In CDI, a producer method must be always annotated with <code>@Produces</code>.</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code data-lang="java" class="language-java hljs">class Producers {

  @Inject
  @ConfigProperty(name = "cool")
  String coolProperty;

  @Produces
  @ApplicationScoped
  MyService produceService() {
    return new MyService(coolProperty);
  }
}</code></pre>
</div>
</div>
<div class="paragraph">
<p>In Quarkus, you can skip the <code>@Produces</code> annotation completely if the producer method is annotated with a scope annotation, a stereotype or a qualifier.</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code data-lang="java" class="language-java hljs">class Producers {

  @ConfigProperty(name = "cool")
  String coolProperty;

  @ApplicationScoped
  MyService produceService() {
    return new MyService(coolProperty);
  }
}</code></pre>
</div>
</div>
</div>
<div class="sect2">
<h3 id="interception-of-static-methods"><a class="anchor" href="#interception-of-static-methods"></a>5.11. Interception of Static Methods</h3>
<div class="paragraph">
<p>The Interceptors specification is clear that <em>around-invoke</em> methods must not be declared static.
However, this restriction was driven mostly by technical limitations.
And since Quarkus is a build-time oriented stack that allows for additional class transformations, those limitations don&#8217;t apply anymore.
It&#8217;s possible to annotate a non-private static method with an interceptor binding:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code data-lang="java" class="language-java hljs">class Services {

  @Logged <i class="conum" data-value="1"></i><b>(1)</b>
  static BigDecimal computePrice(long amout) { <i class="conum" data-value="2"></i><b>(2)</b>
    BigDecimal price;
    // Perform computations...
    return price;
  }
}</code></pre>
</div>
</div>
<div class="colist arabic">
<table>
<tr>
<td><i class="conum" data-value="1"></i><b>1</b></td>
<td><code>Logged</code> is an interceptor binding.</td>
</tr>
<tr>
<td><i class="conum" data-value="2"></i><b>2</b></td>
<td>Each method invocation is intercepted if there is an interceptor associated with <code>Logged</code>.</td>
</tr>
</table>
</div>
<div class="sect3">
<h4 id="limitations-2"><a class="anchor" href="#limitations-2"></a>5.11.1. Limitations</h4>
<div class="ulist">
<ul>
<li>
<p>Only <strong>method-level bindings</strong> are considered for backward compatibility reasons (otherwise static methods of bean classes that declare class-level bindings would be suddenly intercepted)</p>
</li>
<li>
<p>Private static methods are never intercepted</p>
</li>
<li>
<p><code>InvocationContext#getTarget()</code> returns <code>null</code> for obvious reasons; therefore not all existing interceptors may behave correctly when intercepting static methods</p>
<div class="admonitionblock note">
<table>
<tr>
<td class="icon">
<i class="fa icon-note" title="Note"></i>
</td>
<td class="content">
Interceptors can use <code>InvocationContext.getMethod()</code> to detect static methods and adjust the behavior accordingly.
</td>
</tr>
</table>
</div>
</li>
</ul>
</div>
</div>
</div>
<div class="sect2">
<h3 id="ability-to-handle-final-classes-and-methods"><a class="anchor" href="#ability-to-handle-final-classes-and-methods"></a>5.12. Ability to handle 'final' classes and methods</h3>
<div class="paragraph">
<p>In normal CDI, classes that are marked as <code>final</code> and / or have <code>final</code> methods are not eligible for proxy creation,
which in turn means that interceptors and normal scoped beans don&#8217;t work properly.
This situation is very common when trying to use CDI with alternative JVM languages like Kotlin where classes and methods are <code>final</code> by default.</p>
</div>
<div class="paragraph">
<p>Quarkus however, can overcome these limitations when <code>quarkus.arc.transform-unproxyable-classes</code> is set to <code>true</code> (which is the default value).</p>
</div>
</div>
<div class="sect2">
<h3 id="container-managed-concurrency"><a class="anchor" href="#container-managed-concurrency"></a>5.13. Container-managed Concurrency</h3>
<div class="paragraph">
<p>There is no standard concurrency control mechanism for CDI beans.
Nevertheless, a bean instance can be shared and accessed concurrently from multiple threads.
In that case it should be thread-safe.
You can use standard Java constructs (<code>volatile</code>, <code>synchronized</code>, <code>ReadWriteLock</code>, etc.) or let the container control the concurrent access.
Quarkus provides <code>@io.quarkus.arc.Lock</code> and a built-in interceptor for this interceptor binding.
Each interceptor instance associated with a contextual instance of an intercepted bean holds a separate <code>ReadWriteLock</code> with non-fair ordering policy.</p>
</div>
<div class="admonitionblock tip">
<table>
<tr>
<td class="icon">
<i class="fa icon-tip" title="Tip"></i>
</td>
<td class="content">
<code>io.quarkus.arc.Lock</code> is a regular interceptor binding and as such can be used for any bean with any scope. However, it is especially useful for "shared" scopes, e.g. <code>@Singleton</code> and <code>@ApplicationScoped</code>.
</td>
</tr>
</table>
</div>
<div class="listingblock">
<div class="title">Container-managed Concurrency Example</div>
<div class="content">
<pre class="highlightjs highlight"><code data-lang="java" class="language-java hljs">import io.quarkus.arc.Lock;

@Lock <i class="conum" data-value="1"></i><b>(1)</b>
@ApplicationScoped
class SharedService {

  void addAmount(BigDecimal amout) {
    // ...changes some internal state of the bean
  }

  @Lock(value = Lock.Type.READ, time = 1, unit = TimeUnit.SECONDS) <i class="conum" data-value="2"></i><b>(2)</b> <i class="conum" data-value="3"></i><b>(3)</b>
  BigDecimal getAmount() {
    // ...it is safe to read the value concurrently
  }
}</code></pre>
</div>
</div>
<div class="colist arabic">
<table>
<tr>
<td><i class="conum" data-value="1"></i><b>1</b></td>
<td><code>@Lock</code> (which maps to <code>@Lock(Lock.Type.WRITE)</code>) declared on the class instructs the container to lock the bean instance for any invocation of any business method, i.e. the client has "exclusive access" and no concurrent invocations will be allowed.</td>
</tr>
<tr>
<td><i class="conum" data-value="2"></i><b>2</b></td>
<td><code>@Lock(Lock.Type.READ)</code> overrides the value specified at class level. It means that any number of clients can invoke the method concurrently, unless the bean instance is locked by <code>@Lock(Lock.Type.WRITE)</code>.</td>
</tr>
<tr>
<td><i class="conum" data-value="3"></i><b>3</b></td>
<td>You can also specify the "wait time". If it&#8217;s not possible to acquire the lock in the given time a <code>LockException</code> is thrown.</td>
</tr>
</table>
</div>
</div>
</div>
</div>
<div class="sect1">
<h2 id="build_time_apis"><a class="anchor" href="#build_time_apis"></a>6. Build Time Extension Points</h2>
<div class="sectionbody">
<div class="sect2">
<h3 id="portable_extensions"><a class="anchor" href="#portable_extensions"></a>6.1. Portable Extensions</h3>
<div class="paragraph">
<p>Quarkus incorporates build-time optimizations in order to provide instant startup and low memory footprint.
The downside of this approach is that CDI Portable Extensions cannot be supported.
Nevertheless, most of the functionality can be achieved using Quarkus <a href="writing-extensions">extensions</a>.</p>
</div>
</div>
<div class="sect2">
<h3 id="additional-bean-defining-annotations"><a class="anchor" href="#additional-bean-defining-annotations"></a>6.2. Additional Bean Defining Annotations</h3>
<div class="paragraph">
<p>As described in <a href="#bean_discovery">Bean Discovery</a> bean classes that don’t have a bean defining annotation are not discovered.
However, <code>BeanDefiningAnnotationBuildItem</code> can be used to extend the set of default bean defining annotations (<code>@Dependent</code>, <code>@Singleton</code>, <code>@ApplicationScoped</code>, <code>@RequestScoped</code> and <code>@Stereotype</code> annotations):</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code data-lang="java" class="language-java hljs">@BuildStep
BeanDefiningAnnotationBuildItem additionalBeanDefiningAnnotation() {
    return new BeanDefiningAnnotationBuildItem(DotName.createSimple("javax.ws.rs.Path")));
}</code></pre>
</div>
</div>
<div class="admonitionblock note">
<table>
<tr>
<td class="icon">
<i class="fa icon-note" title="Note"></i>
</td>
<td class="content">
Bean registrations that are result of a <code>BeanDefiningAnnotationBuildItem</code> are unremovable by default. See also <a href="#remove_unused_beans">Removing Unused Beans</a>.
</td>
</tr>
</table>
</div>
</div>
<div class="sect2">
<h3 id="resource-annotations"><a class="anchor" href="#resource-annotations"></a>6.3. Resource Annotations</h3>
<div class="paragraph">
<p><code>ResourceAnnotationBuildItem</code> is used to specify resource annotations  that make it possible to resolve non-CDI injection points, such as Java EE resources.</p>
</div>
<div class="admonitionblock note">
<table>
<tr>
<td class="icon">
<i class="fa icon-note" title="Note"></i>
</td>
<td class="content">
An integrator must also provide a corresponding <code>io.quarkus.arc.ResourceReferenceProvider</code> implementation.
</td>
</tr>
</table>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code data-lang="java" class="language-java hljs">@BuildStep
void setupResourceInjection(BuildProducer&lt;ResourceAnnotationBuildItem&gt; resourceAnnotations, BuildProducer&lt;GeneratedResourceBuildItem&gt; resources) {
    resources.produce(new GeneratedResourceBuildItem("META-INF/services/io.quarkus.arc.ResourceReferenceProvider",
        JPAResourceReferenceProvider.class.getName().getBytes()));
    resourceAnnotations.produce(new ResourceAnnotationBuildItem(DotName.createSimple(PersistenceContext.class.getName())));
}</code></pre>
</div>
</div>
</div>
<div class="sect2">
<h3 id="additional_beans"><a class="anchor" href="#additional_beans"></a>6.4. Additional Beans</h3>
<div class="paragraph">
<p><code>AdditionalBeanBuildItem</code> is used to specify additional bean classes to be analyzed during discovery.
Additional bean classes are transparently added to the application index processed by the container.</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code data-lang="java" class="language-java hljs">@BuildStep
List&lt;AdditionalBeanBuildItem&gt; additionalBeans() {
     return Arrays.asList(
          new AdditionalBeanBuildItem(SmallRyeHealthReporter.class),
          new AdditionalBeanBuildItem(HealthServlet.class));
}</code></pre>
</div>
</div>
<div class="admonitionblock note">
<table>
<tr>
<td class="icon">
<i class="fa icon-note" title="Note"></i>
</td>
<td class="content">
A bean registration that is a result of an <code>AdditionalBeanBuildItem</code> is removable by default. See also <a href="#remove_unused_beans">Removing Unused Beans</a>.
</td>
</tr>
</table>
</div>
</div>
<div class="sect2">
<h3 id="synthetic_beans"><a class="anchor" href="#synthetic_beans"></a>6.5. Synthetic Beans</h3>
<div class="paragraph">
<p>Sometimes it is very useful to be able to register a synthetic bean.
Bean attributes of a synthetic bean are not derived from a java class, method or field.
Instead, the attributes are specified by an extension.
In CDI, this could be achieved using the <code>AfterBeanDiscovery.addBean()</code> methods.
In Quarkus, there are three ways to register a synthetic bean.</p>
</div>
<div class="sect3">
<h4 id="beanregistrarbuilditem"><a class="anchor" href="#beanregistrarbuilditem"></a>6.5.1. <code>BeanRegistrarBuildItem</code></h4>
<div class="paragraph">
<p>A build step can produce a <code>BeanRegistrarBuildItem</code> and leverage the <code>io.quarkus.arc.processor.BeanConfigurator</code> API to build a synthetic bean definition.</p>
</div>
<div class="listingblock">
<div class="title"><code>BeanRegistrarBuildItem</code> Example</div>
<div class="content">
<pre class="highlightjs highlight"><code data-lang="java" class="language-java hljs">@BuildStep
BeanRegistrarBuildItem syntheticBean() {
     return new BeanRegistrarBuildItem(new BeanRegistrar() {

            @Override
            public void register(RegistrationContext registrationContext) {
                 registrationContext.configure(String.class).types(String.class).qualifiers(new MyQualifierLiteral()).creator(mc -&gt; mc.returnValue(mc.load("foo"))).done();
            }
        }));
}</code></pre>
</div>
</div>
<div class="admonitionblock note">
<table>
<tr>
<td class="icon">
<i class="fa icon-note" title="Note"></i>
</td>
<td class="content">
The output of a <code>BeanConfigurator</code> is recorded as bytecode. Therefore there are some limitations in how a synthetic bean instance is created. See also <code>BeanConfigurator.creator()</code> methods.
</td>
</tr>
</table>
</div>
<div class="admonitionblock tip">
<table>
<tr>
<td class="icon">
<i class="fa icon-tip" title="Tip"></i>
</td>
<td class="content">
You can easily filter all class-based beans via the convenient <code>BeanStream</code> returned from the <code>RegistrationContext.beans()</code> method.
</td>
</tr>
</table>
</div>
</div>
<div class="sect3">
<h4 id="beanregistrationphasebuilditem"><a class="anchor" href="#beanregistrationphasebuilditem"></a>6.5.2. <code>BeanRegistrationPhaseBuildItem</code></h4>
<div class="paragraph">
<p>If a build step <strong>needs to produce other build items during the registration</strong> it should use the <code>BeanRegistrationPhaseBuildItem</code>.
The reason is that injected objects are only valid during a <code>@BuildStep</code> method invocation.</p>
</div>
<div class="listingblock">
<div class="title"><code>BeanRegistrationPhaseBuildItem</code> Example</div>
<div class="content">
<pre class="highlightjs highlight"><code data-lang="java" class="language-java hljs">@BuildStep
void syntheticBean(BeanRegistrationPhaseBuildItem beanRegistrationPhase,
            BuildProducer&lt;MyBuildItem&gt; myBuildItem,
            BuildProducer&lt;BeanConfiguratorBuildItem&gt; beanConfigurators) {
   beanConfigurators.produce(new BeanConfiguratorBuildItem(beanRegistrationPhase.getContext().configure(String.class).types(String.class).qualifiers(new MyQualifierLiteral()).creator(mc -&gt; mc.returnValue(mc.load("foo")))));
   myBuildItem.produce(new MyBuildItem());
}</code></pre>
</div>
</div>
<div class="admonitionblock note">
<table>
<tr>
<td class="icon">
<i class="fa icon-note" title="Note"></i>
</td>
<td class="content">
See the <code>BeanRegistrationPhaseBuildItem</code> javadoc for more information.
</td>
</tr>
</table>
</div>
</div>
<div class="sect3">
<h4 id="syntheticbeanbuilditem"><a class="anchor" href="#syntheticbeanbuilditem"></a>6.5.3. <code>SyntheticBeanBuildItem</code></h4>
<div class="paragraph">
<p>Finally, a build step can produce a <code>SyntheticBeanBuildItem</code> to register a synthetic bean whose instance can be easily <strong>produced through a <a href="writing-extensions#bytecode-recording">recorder</a></strong>.
The extended <code>BeanConfigurator</code> accepts either a <code>io.quarkus.runtime.RuntimeValue</code> or a <code>java.util.function.Supplier</code>.</p>
</div>
<div class="listingblock">
<div class="title"><code>SyntheticBeanBuildItem</code> Example</div>
<div class="content">
<pre class="highlightjs highlight"><code data-lang="java" class="language-java hljs">@BuildStep
@Record(STATIC_INIT)
SyntheticBeanBuildItem syntheticBean(TestRecorder recorder) {
   return SyntheticBeanBuildItem.configure(Foo.class).scope(Singleton.class)
                .runtimeValue(recorder.createFoo())
                .done();
}</code></pre>
</div>
</div>
</div>
</div>
<div class="sect2">
<h3 id="annotation-transformations"><a class="anchor" href="#annotation-transformations"></a>6.6. Annotation Transformations</h3>
<div class="paragraph">
<p>A very common task is to override the annotations found on the bean classes.
For example you might want to add an interceptor binding to a specific bean class.
Here is how to do it - use the <code>AnnotationsTransformerBuildItem</code>:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code data-lang="java" class="language-java hljs">@BuildStep
AnnotationsTransformerBuildItem transform() {
    return new AnnotationsTransformerBuildItem(new AnnotationsTransformer() {

        public boolean appliesTo(org.jboss.jandex.AnnotationTarget.Kind kind) {
            return kind == org.jboss.jandex.AnnotationTarget.Kind.CLASS;
        }

        public void transform(TransformationContext context) {
            if (context.getTarget().asClass().name().toString().equals("com.foo.Bar")) {
                context.transform().add(MyInterceptorBinding.class).done();
            }
        }
    });
}</code></pre>
</div>
</div>
</div>
<div class="sect2">
<h3 id="additional-interceptor-bindings"><a class="anchor" href="#additional-interceptor-bindings"></a>6.7. Additional Interceptor Bindings</h3>
<div class="paragraph">
<p>In rare cases it might be handy to programmatically register an existing annotation as interceptor binding.
This is similar to what pure CDI achieves through <code>BeforeBeanDiscovery#addInterceptorBinding()</code>.
Though here we are going to use <code>InterceptorBindingRegistrarBuildItem</code> to get it done.
Note that you can register multiple annotations in one go:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code data-lang="java" class="language-java hljs">@BuildStep
InterceptorBindingRegistrarBuildItem addInterceptorBindings() {
    InterceptorBindingRegistrarBuildItem additionalBindingsRegistrar = new InterceptorBindingRegistrarBuildItem(new InterceptorBindingRegistrar() {
        @Override
        public Collection&lt;DotName&gt; registerAdditionalBindings() {
            Collection&lt;DotName&gt; result = new HashSet&lt;&gt;();
            result.add(DotName.createSimple(MyAnnotation.class.getName()));
            result.add(DotName.createSimple(MyOtherAnnotation.class.getName()));
            return result;
        }
    });
    return additionalBindingsRegistrar;
}</code></pre>
</div>
</div>
</div>
<div class="sect2">
<h3 id="injection-point-transformation"><a class="anchor" href="#injection-point-transformation"></a>6.8. Injection Point Transformation</h3>
<div class="paragraph">
<p>Every now and then it is handy to be able to change qualifiers of an injection point programmatically.
You can do just that with <code>InjectionPointTransformerBuildItem</code>.
The following sample shows how to apply transformation to injection points with type <code>Foo</code> that contain qualifier <code>MyQualifier</code>:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code data-lang="java" class="language-java hljs">@BuildStep
InjectionPointTransformerBuildItem transformer() {
    return new InjectionPointTransformerBuildItem(new InjectionPointsTransformer() {

        public boolean appliesTo(Type requiredType) {
            return requiredType.name().equals(DotName.createSimple(Foo.class.getName()));
        }

        public void transform(TransformationContext context) {
            if (context.getQualifiers().stream()
                    .anyMatch(a -&gt; a.name().equals(DotName.createSimple(MyQualifier.class.getName())))) {
                context.transform()
                        .removeAll()
                        .add(DotName.createSimple(MyOtherQualifier.class.getName()))
                        .done();
            }
        }
    });
}</code></pre>
</div>
</div>
</div>
<div class="sect2">
<h3 id="observer-transformation"><a class="anchor" href="#observer-transformation"></a>6.9. Observer Transformation</h3>
<div class="paragraph">
<p>Any <a href="https://docs.jboss.org/cdi/spec/2.0/cdi-spec.html#observer_methods">observer method</a> definition can be vetoed or transformed using an <code>ObserverTransformerBuildItem</code>.
The attributes that can be transformed include:</p>
</div>
<div class="ulist">
<ul>
<li>
<p><a href="https://docs.jboss.org/cdi/api/2.0/javax/enterprise/inject/spi/ObserverMethod.html#getObservedQualifiers--">qualifiers</a></p>
</li>
<li>
<p><a href="https://docs.jboss.org/cdi/api/2.0/javax/enterprise/inject/spi/ObserverMethod.html#getReception--">reception</a></p>
</li>
<li>
<p><a href="https://docs.jboss.org/cdi/api/2.0/javax/enterprise/inject/spi/ObserverMethod.html#getPriority--">priority</a></p>
</li>
<li>
<p><a href="https://docs.jboss.org/cdi/api/2.0/javax/enterprise/inject/spi/ObserverMethod.html#getTransactionPhase--">transaction phase</a></p>
</li>
<li>
<p><a href="https://docs.jboss.org/cdi/api/2.0/javax/enterprise/inject/spi/ObserverMethod.html#isAsync--">asynchronous</a></p>
</li>
</ul>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code data-lang="java" class="language-java hljs">@BuildStep
ObserverTransformerBuildItem transformer() {
    return new ObserverTransformerBuildItem(new ObserverTransformer() {

        public boolean appliesTo(Type observedType, Set&lt;AnnotationInstance&gt; qualifiers) {
            return observedType.name.equals(DotName.createSimple(MyEvent.class.getName()));
        }

        public void transform(TransformationContext context) {
            // Veto all observers of MyEvent
            context.veto();
        }
    });
}</code></pre>
</div>
</div>
</div>
<div class="sect2">
<h3 id="bean-deployment-validation"><a class="anchor" href="#bean-deployment-validation"></a>6.10. Bean Deployment Validation</h3>
<div class="paragraph">
<p>Once the bean deployment is ready an extension can perform additional validations and inspect the found beans, observers and injection points.
Register a <code>BeanDeploymentValidatorBuildItem</code>:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code data-lang="java" class="language-java hljs">@BuildStep
BeanDeploymentValidatorBuildItem beanDeploymentValidator() {
    return new BeanDeploymentValidatorBuildItem(new BeanDeploymentValidator() {
         public void validate(ValidationContext validationContext) {
             for (InjectionPointInfo injectionPoint : validationContext.get(Key.INJECTION_POINTS)) {
                 System.out.println("Injection point: " + injectionPoint);
             }
         }
    });
}</code></pre>
</div>
</div>
<div class="admonitionblock tip">
<table>
<tr>
<td class="icon">
<i class="fa icon-tip" title="Tip"></i>
</td>
<td class="content">
You can easily filter all registered beans via the convenient <code>BeanStream</code> returned from the <code>ValidationContext.beans()</code> method.
</td>
</tr>
</table>
</div>
<div class="paragraph">
<p>If an extension needs to produce other build items during the "validation" phase it should use the <code>ValidationPhaseBuildItem</code> instead.
The reason is that injected objects are only valid during a <code>@BuildStep</code> method invocation.</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code data-lang="java" class="language-java hljs">@BuildStep
void validate(ValidationPhaseBuildItem validationPhase,
            BuildProducer&lt;MyBuildItem&gt; myBuildItem,
            BuildProducer&lt;ValidationErrorBuildItem&gt; errors) {
   if (someCondition) {
     errors.produce(new ValidationErrorBuildItem(new IllegalStateException()));
     myBuildItem.produce(new MyBuildItem());
   }
}</code></pre>
</div>
</div>
<div class="admonitionblock note">
<table>
<tr>
<td class="icon">
<i class="fa icon-note" title="Note"></i>
</td>
<td class="content">
See <code>ValidationPhaseBuildItem</code> javadoc for more information.
</td>
</tr>
</table>
</div>
</div>
<div class="sect2">
<h3 id="custom-contexts"><a class="anchor" href="#custom-contexts"></a>6.11. Custom Contexts</h3>
<div class="paragraph">
<p>An extension can register a custom <code>InjectableContext</code> implementation by means of a <code>ContextRegistrarBuildItem</code>:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code data-lang="java" class="language-java hljs">@BuildStep
ContextRegistrarBuildItem customContext() {
    return new ContextRegistrarBuildItem(new ContextRegistrar() {
         public void register(RegistrationContext registrationContext) {
            registrationContext.configure(CustomScoped.class).normal().contextClass(MyCustomContext.class).done();
         }
    });
}</code></pre>
</div>
</div>
<div class="paragraph">
<p>If an extension needs to produce other build items during the "context registration" phase it should use the <code>ContextRegistrationPhaseBuildItem</code> instead.
The reason is that injected objects are only valid during a <code>@BuildStep</code> method invocation.</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code data-lang="java" class="language-java hljs">@BuildStep
void addContext(ContextRegistrationPhaseBuildItem contextRegistrationPhase,
            BuildProducer&lt;MyBuildItem&gt; myBuildItem,
            BuildProducer&lt;ContextConfiguratorBuildItem&gt; contexts) {
   contexts.produce(new ContextConfiguratorBuildItem(contextRegistrationPhase.getContext().configure(CustomScoped.class).normal().contextClass(MyCustomContext.class)));
   myBuildItem.produce(new MyBuildItem());
}</code></pre>
</div>
</div>
<div class="admonitionblock note">
<table>
<tr>
<td class="icon">
<i class="fa icon-note" title="Note"></i>
</td>
<td class="content">
See <code>ContextRegistrationPhaseBuildItem</code> javadoc for more information.
</td>
</tr>
</table>
</div>
</div>
<div class="sect2">
<h3 id="build_metadata"><a class="anchor" href="#build_metadata"></a>6.12. Available Build Time Metadata</h3>
<div class="paragraph">
<p>Any of the above extensions that operates with <code>BuildExtension.BuildContext</code> can leverage certain build time metadata that are generated during build.
The built-in keys located in <code>io.quarkus.arc.processor.BuildExtension.Key</code> are:</p>
</div>
<div class="ulist">
<ul>
<li>
<p><code>ANNOTATION_STORE</code></p>
<div class="ulist">
<ul>
<li>
<p>Contains an <code>AnnotationStore</code> that keeps information about all <code>AnnotationTarget</code> annotations after application of annotation transformers</p>
</li>
</ul>
</div>
</li>
<li>
<p><code>INJECTION_POINTS</code></p>
<div class="ulist">
<ul>
<li>
<p><code>Collection&lt;InjectionPointInfo&gt;</code> containing all injection points</p>
</li>
</ul>
</div>
</li>
<li>
<p><code>BEANS</code></p>
<div class="ulist">
<ul>
<li>
<p><code>Collection&lt;BeanInfo&gt;</code> containing all beans</p>
</li>
</ul>
</div>
</li>
<li>
<p><code>REMOVED_BEANS</code></p>
<div class="ulist">
<ul>
<li>
<p><code>Collection&lt;BeanInfo&gt;</code> containing all the removed beans; see <a href="#remove_unused_beans">Removing Unused Beans</a> for more information</p>
</li>
</ul>
</div>
</li>
<li>
<p><code>OBSERVERS</code></p>
<div class="ulist">
<ul>
<li>
<p><code>Collection&lt;ObserverInfo&gt;</code> containing all observers</p>
</li>
</ul>
</div>
</li>
<li>
<p><code>SCOPES</code></p>
<div class="ulist">
<ul>
<li>
<p><code>Collection&lt;ScopeInfo&gt;</code> containing all scopes, including custom ones</p>
</li>
</ul>
</div>
</li>
<li>
<p><code>QUALIFIERS</code></p>
<div class="ulist">
<ul>
<li>
<p><code>Map&lt;DotName, ClassInfo&gt;</code> containing all qualifiers</p>
</li>
</ul>
</div>
</li>
<li>
<p><code>INTERCEPTOR_BINDINGS</code></p>
<div class="ulist">
<ul>
<li>
<p><code>Map&lt;DotName, ClassInfo&gt;</code> containing all interceptor bindings</p>
</li>
</ul>
</div>
</li>
<li>
<p><code>STEREOTYPES</code></p>
<div class="ulist">
<ul>
<li>
<p><code>Map&lt;DotName, ClassInfo&gt;</code> containing all stereotypes</p>
</li>
</ul>
</div>
</li>
</ul>
</div>
<div class="paragraph">
<p>To get hold of these, simply query the extension context object for given key.
Note that these metadata are made available as build proceeds which means that extensions can only leverage metadata that were build before they are invoked.
If your extension attempts to retrieve metadata that wasn&#8217;t yet produced, <code>null</code> will be returned.
Here is a summary of which extensions can access which metadata:</p>
</div>
<div class="ulist">
<ul>
<li>
<p><code>AnnotationsTransformer</code></p>
<div class="ulist">
<ul>
<li>
<p>Shouldn&#8217;t rely on any metadata as this is one of the first CDI extensions invoked</p>
</li>
</ul>
</div>
</li>
<li>
<p><code>ContextRegistrar</code></p>
<div class="ulist">
<ul>
<li>
<p>Has access to <code>ANNOTATION_STORE</code></p>
</li>
</ul>
</div>
</li>
<li>
<p><code>InjectionPointsTransformer</code></p>
<div class="ulist">
<ul>
<li>
<p>Has access to <code>ANNOTATION_STORE</code>, <code>QUALIFIERS</code>, <code>INTERCEPTOR_BINDINGS</code>, <code>STEREOTYPES</code></p>
</li>
</ul>
</div>
</li>
<li>
<p><code>ObserverTransformer</code></p>
<div class="ulist">
<ul>
<li>
<p>Has access to <code>ANNOTATION_STORE</code>, <code>QUALIFIERS</code>, <code>INTERCEPTOR_BINDINGS</code>, <code>STEREOTYPES</code></p>
</li>
</ul>
</div>
</li>
<li>
<p><code>BeanRegistrar</code></p>
<div class="ulist">
<ul>
<li>
<p>Has access to <code>ANNOTATION_STORE</code>, <code>QUALIFIERS</code>, <code>INTERCEPTOR_BINDINGS</code>, <code>STEREOTYPES</code>, <code>BEANS</code></p>
</li>
</ul>
</div>
</li>
<li>
<p><code>BeanDeploymentValidator</code></p>
<div class="ulist">
<ul>
<li>
<p>Has access to all build metadata</p>
</li>
</ul>
</div>
</li>
</ul>
</div>
</div>
</div>
</div>
<div class="sect1">
<h2 id="dev-mode"><a class="anchor" href="#dev-mode"></a>7. Development Mode</h2>
<div class="sectionbody">
<div class="paragraph">
<p>In the development mode, two special endpoints are registered automatically to provide some basic debug info in the JSON format:</p>
</div>
<div class="ulist">
<ul>
<li>
<p>HTTP GET <code>/quarkus/arc/beans</code> - returns the list of all beans</p>
<div class="ulist">
<ul>
<li>
<p>You can use query params to filter the output:</p>
<div class="ulist">
<ul>
<li>
<p><code>scope</code> - include beans with scope that ends with the given value, i.e. <code><a href="http://localhost:8080/quarkus/arc/beans?scope=ApplicationScoped" class="bare">http://localhost:8080/quarkus/arc/beans?scope=ApplicationScoped</a></code></p>
</li>
<li>
<p><code>beanClass</code> - include beans with bean class that starts with the given value, i.e. <code><a href="http://localhost:8080/quarkus/arc/beans?beanClass=org.acme.Foo" class="bare">http://localhost:8080/quarkus/arc/beans?beanClass=org.acme.Foo</a></code></p>
</li>
<li>
<p><code>kind</code> - include beans of the specified kind (<code>CLASS</code>, <code>PRODUCER_FIELD</code>, <code>PRODUCER_METHOD</code>, <code>INTERCEPTOR</code> or <code>SYNTHETIC</code>), i.e. <code><a href="http://localhost:8080/quarkus/arc/beans?kind=PRODUCER_METHOD" class="bare">http://localhost:8080/quarkus/arc/beans?kind=PRODUCER_METHOD</a></code></p>
</li>
</ul>
</div>
</li>
</ul>
</div>
</li>
<li>
<p>HTTP GET <code>/quarkus/arc/observers</code> - returns the list of all observer methods</p>
</li>
</ul>
</div>
<div class="admonitionblock note">
<table>
<tr>
<td class="icon">
<i class="fa icon-note" title="Note"></i>
</td>
<td class="content">
These endpoints are only available in the development mode, i.e. when you run your application via <code>mvn quarkus:dev</code> (or <code>./gradlew quarkusDev</code>).
</td>
</tr>
</table>
</div>
</div>
</div>
<div class="sect1">
<h2 id="arc-configuration-reference"><a class="anchor" href="#arc-configuration-reference"></a>8. ArC Configuration Reference</h2>
<div class="sectionbody">
<div class="paragraph configuration-legend">
<p><span class="icon"><i class="fa fa-lock" title="Fixed at build time"></i></span> Configuration property fixed at build time - All other configuration properties are overridable at runtime</p>
</div>
<table class="tableblock frame-all grid-all stretch configuration-reference searchable">
<colgroup>
<col style="width: 80%;">
<col style="width: 10%;">
<col style="width: 10%;">
</colgroup>
<tbody>
<tr>
<th class="tableblock halign-left valign-top"><p class="tableblock"><a id="quarkus-arc_configuration"></a><a href="#quarkus-arc_configuration">Configuration property</a></p></th>
<th class="tableblock halign-left valign-middle"><p class="tableblock">Type</p></th>
<th class="tableblock halign-left valign-middle"><p class="tableblock">Default</p></th>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
<p><span class="icon"><i class="fa fa-lock" title="Fixed at build time"></i></span> <a id="quarkus-arc_quarkus.arc.remove-unused-beans"></a><code><a href="#quarkus-arc_quarkus.arc.remove-unused-beans">quarkus.arc.remove-unused-beans</a></code></p>
</div>
<div class="openblock description">
<div class="content">
<div class="ulist">
<ul>
<li>
<p>If set to <code>all</code> (or <code>true</code>) the container will attempt to remove all unused beans.</p>
</li>
<li>
<p>If set to <code>none</code> (or <code>false</code>) no beans will ever be removed even if they are unused (according to the criteria set out below)</p>
</li>
<li>
<p>If set to <code>fwk</code>, then all unused beans will be removed, except the unused beans whose classes are declared in the application code
An unused bean:</p>
</li>
<li>
<p>is not a built-in bean or interceptor,</p>
</li>
<li>
<p>is not eligible for injection to any injection point,</p>
</li>
<li>
<p>is not excluded by any extension,</p>
</li>
<li>
<p>does not have a name,</p>
</li>
<li>
<p>does not declare an observer,</p>
</li>
<li>
<p>does not declare any producer which is eligible for injection to any injection point,</p>
</li>
<li>
<p>is not directly eligible for injection into any <code>javax.enterprise.inject.Instance</code> injection point</p>
</li>
</ul>
</div>
</div>
</div></div></td>
<td class="tableblock halign-left valign-middle"><p class="tableblock">string</p></td>
<td class="tableblock halign-left valign-middle"><p class="tableblock"><code>all</code></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
<p><span class="icon"><i class="fa fa-lock" title="Fixed at build time"></i></span> <a id="quarkus-arc_quarkus.arc.auto-inject-fields"></a><code><a href="#quarkus-arc_quarkus.arc.auto-inject-fields">quarkus.arc.auto-inject-fields</a></code></p>
</div>
<div class="openblock description">
<div class="content">
<div class="paragraph">
<p>If set to true <code>@Inject</code> is automatically added to all non-static fields that are annotated with one of the annotations defined by <code>AutoInjectAnnotationBuildItem</code>.</p>
</div>
</div>
</div></div></td>
<td class="tableblock halign-left valign-middle"><p class="tableblock">boolean</p></td>
<td class="tableblock halign-left valign-middle"><p class="tableblock"><code>true</code></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
<p><span class="icon"><i class="fa fa-lock" title="Fixed at build time"></i></span> <a id="quarkus-arc_quarkus.arc.transform-unproxyable-classes"></a><code><a href="#quarkus-arc_quarkus.arc.transform-unproxyable-classes">quarkus.arc.transform-unproxyable-classes</a></code></p>
</div>
<div class="openblock description">
<div class="content">
<div class="paragraph">
<p>If set to true, the bytecode of unproxyable beans will be transformed. This ensures that a proxy/subclass can be created properly. If the value is set to false, then an exception is thrown at build time indicating that a subclass/proxy could not be created. Quarkus performs the following transformations when this setting is enabled:
 - Remove 'final' modifier from classes and methods when a proxy is required.
 - Create a no-args constructor if needed.
 - Makes private no-args constructors package-private if necessary.</p>
</div>
</div>
</div></div></td>
<td class="tableblock halign-left valign-middle"><p class="tableblock">boolean</p></td>
<td class="tableblock halign-left valign-middle"><p class="tableblock"><code>true</code></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
<p><span class="icon"><i class="fa fa-lock" title="Fixed at build time"></i></span> <a id="quarkus-arc_quarkus.arc.config-properties-default-naming-strategy"></a><code><a href="#quarkus-arc_quarkus.arc.config-properties-default-naming-strategy">quarkus.arc.config-properties-default-naming-strategy</a></code></p>
</div>
<div class="openblock description">
<div class="content">
<div class="paragraph">
<p>The default naming strategy for <code>ConfigProperties.NamingStrategy</code>. The allowed values are determined by that enum</p>
</div>
</div>
</div></div></td>
<td class="tableblock halign-left valign-middle"><p class="tableblock"><code>from-config</code>, <code>verbatim</code>, <code>kebab-case</code></p></td>
<td class="tableblock halign-left valign-middle"><p class="tableblock"><code>kebab-case</code></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
<p><span class="icon"><i class="fa fa-lock" title="Fixed at build time"></i></span> <a id="quarkus-arc_quarkus.arc.selected-alternatives"></a><code><a href="#quarkus-arc_quarkus.arc.selected-alternatives">quarkus.arc.selected-alternatives</a></code></p>
</div>
<div class="openblock description">
<div class="content">
<div class="paragraph">
<p>The list of selected alternatives for an application.
 An element value can be:
 - a fully qualified class name, i.e. <code>org.acme.Foo</code>
 - a simple class name as defined by <code>Class#getSimpleName()</code>, i.e. <code>Foo</code>
 - a package name with suffix <code>.*</code>, i.e. <code>org.acme.*</code>, matches a package
 - a package name with suffix <code>.**</code>, i.e. <code>org.acme.**</code>, matches a package that starts with the value  Each element value is used to match an alternative bean class, an alternative stereotype annotation type or a bean class that declares an alternative producer. If any value matches then the priority of <code>Integer#MAX_VALUE</code> is used for the relevant bean. The priority declared via <code>javax.annotation.Priority</code> or <code>io.quarkus.arc.AlternativePriority</code> is overriden.</p>
</div>
</div>
</div></div></td>
<td class="tableblock halign-left valign-middle"><p class="tableblock">list of string</p></td>
<td class="tableblock halign-left valign-middle"></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
<p><span class="icon"><i class="fa fa-lock" title="Fixed at build time"></i></span> <a id="quarkus-arc_quarkus.arc.auto-producer-methods"></a><code><a href="#quarkus-arc_quarkus.arc.auto-producer-methods">quarkus.arc.auto-producer-methods</a></code></p>
</div>
<div class="openblock description">
<div class="content">
<div class="paragraph">
<p>If set to true then <code>javax.enterprise.inject.Produces</code> is automatically added to all methods that are annotated with a scope annotation, a stereotype or a qualifier, and are not annotated with <code>Inject</code> or <code>Produces</code>, and no parameter is annotated with <code>Disposes</code>, <code>Observes</code> or <code>ObservesAsync</code>.</p>
</div>
</div>
</div></div></td>
<td class="tableblock halign-left valign-middle"><p class="tableblock">boolean</p></td>
<td class="tableblock halign-left valign-middle"><p class="tableblock"><code>true</code></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
<p><span class="icon"><i class="fa fa-lock" title="Fixed at build time"></i></span> <a id="quarkus-arc_quarkus.arc.exclude-types"></a><code><a href="#quarkus-arc_quarkus.arc.exclude-types">quarkus.arc.exclude-types</a></code></p>
</div>
<div class="openblock description">
<div class="content">
<div class="paragraph">
<p>The list of types that should be excluded from discovery.
 An element value can be:
 - a fully qualified class name, i.e. <code>org.acme.Foo</code>
 - a simple class name as defined by <code>Class#getSimpleName()</code>, i.e. <code>Foo</code>
 - a package name with suffix <code>.*</code>, i.e. <code>org.acme.*</code>, matches a package
 - a package name with suffix <code>.**</code>, i.e. <code>org.acme.**</code>, matches a package that starts with the value  If any element value matches a discovered type then the type is excluded from discovery, i.e. no beans and observer methods are created from this type.</p>
</div>
</div>
</div></div></td>
<td class="tableblock halign-left valign-middle"><p class="tableblock">list of string</p></td>
<td class="tableblock halign-left valign-middle"></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
<p><span class="icon"><i class="fa fa-lock" title="Fixed at build time"></i></span> <a id="quarkus-arc_quarkus.arc.unremovable-types"></a><code><a href="#quarkus-arc_quarkus.arc.unremovable-types">quarkus.arc.unremovable-types</a></code></p>
</div>
<div class="openblock description">
<div class="content">
<div class="paragraph">
<p>List of types that should be considered unremovable regardless of whether they are directly used or not. This is a configuration option equivalent to using <code>io.quarkus.arc.Unremovable</code> annotation.
 An element value can be:
 - a fully qualified class name, i.e. <code>org.acme.Foo</code>
 - a simple class name as defined by <code>Class#getSimpleName()</code>, i.e. <code>Foo</code>
 - a package name with suffix <code>.*</code>, i.e. <code>org.acme.*</code>, matches a package
 - a package name with suffix <code>.**</code>, i.e. <code>org.acme.**</code>, matches a package that starts with the value  If any element value matches a discovered bean, then such a bean is considered unremovable.</p>
</div>
</div>
</div></div></td>
<td class="tableblock halign-left valign-middle"><p class="tableblock">list of string</p></td>
<td class="tableblock halign-left valign-middle"></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
<p><span class="icon"><i class="fa fa-lock" title="Fixed at build time"></i></span> <a id="quarkus-arc_quarkus.arc.exclude-dependency.-exclude-dependency-.group-id"></a><code><a href="#quarkus-arc_quarkus.arc.exclude-dependency.-exclude-dependency-.group-id">quarkus.arc.exclude-dependency."exclude-dependency".group-id</a></code></p>
</div>
<div class="openblock description">
<div class="content">
<div class="paragraph">
<p>The maven groupId of the artifact to index</p>
</div>
</div>
</div></div></td>
<td class="tableblock halign-left valign-middle"><p class="tableblock">string</p></td>
<td class="tableblock halign-left valign-middle"><p class="tableblock">required <span class="icon"><i class="fa fa-exclamation-circle" title="Configuration property is required"></i></span></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
<p><span class="icon"><i class="fa fa-lock" title="Fixed at build time"></i></span> <a id="quarkus-arc_quarkus.arc.exclude-dependency.-exclude-dependency-.artifact-id"></a><code><a href="#quarkus-arc_quarkus.arc.exclude-dependency.-exclude-dependency-.artifact-id">quarkus.arc.exclude-dependency."exclude-dependency".artifact-id</a></code></p>
</div>
<div class="openblock description">
<div class="content">
<div class="paragraph">
<p>The maven artifactId of the artifact to index</p>
</div>
</div>
</div></div></td>
<td class="tableblock halign-left valign-middle"><p class="tableblock">string</p></td>
<td class="tableblock halign-left valign-middle"><p class="tableblock">required <span class="icon"><i class="fa fa-exclamation-circle" title="Configuration property is required"></i></span></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
<p><span class="icon"><i class="fa fa-lock" title="Fixed at build time"></i></span> <a id="quarkus-arc_quarkus.arc.exclude-dependency.-exclude-dependency-.classifier"></a><code><a href="#quarkus-arc_quarkus.arc.exclude-dependency.-exclude-dependency-.classifier">quarkus.arc.exclude-dependency."exclude-dependency".classifier</a></code></p>
</div>
<div class="openblock description">
<div class="content">
<div class="paragraph">
<p>The maven classifier of the artifact to index</p>
</div>
</div>
</div></div></td>
<td class="tableblock halign-left valign-middle"><p class="tableblock">string</p></td>
<td class="tableblock halign-left valign-middle"></td>
</tr>
</tbody>
</table>
</div>
</div>
    </div>
  </div>
</div>

  </div>

  <div class="content project-footer">
  <div class="footer-section">
    <div class="logo-wrapper">
      <a href="/"><img src="/assets/images/quarkus_logo_horizontal_rgb_reverse.svg" class="project-logo" title="Quarkus"></a>
    </div>
  </div>
  <div class="grid-wrapper">
    <p class="grid__item width-3-12">Quarkus is open. All dependencies of this project are available under the <a href='https://www.apache.org/licenses/LICENSE-2.0' target='_blank'>Apache Software License 2.0</a> or compatible license.<br /><br />This website was built with <a href='https://jekyllrb.com/' target='_blank'>Jekyll</a>, is hosted on <a href='https://pages.github.com/' target='_blank'>Github Pages</a> and is completely open source. If you want to make it better, <a href='https://github.com/quarkusio/quarkusio.github.io' target='_blank'>fork the website</a> and show us what you’ve got.</p>

    
      <div class="width-1-12 project-links">
        <span>Navigation</span>
        <ul class="footer-links width-1-12">
          
            <li><a href="/">Home</a></li>
          
            <li><a href="/guides">Guides</a></li>
          
            <li><a href="/community/#contributing">Contribute</a></li>
          
            <li><a href="/faq">FAQ</a></li>
          
            <li><a href="/get-started">Get Started</a></li>
          
        </ul>
      </div>
    
      <div class="width-1-12 project-links">
        <span>Contribute</span>
        <ul class="footer-links width-1-12">
          
            <li><a href="https://twitter.com/quarkusio">Follow us</a></li>
          
            <li><a href="https://github.com/quarkusio">GitHub</a></li>
          
            <li><a href="/security">Security&nbsp;policy</a></li>
          
        </ul>
      </div>
    
      <div class="width-1-12 project-links">
        <span>Get Help</span>
        <ul class="footer-links width-1-12">
          
            <li><a href="https://groups.google.com/forum/#!forum/quarkus-dev">Forums</a></li>
          
            <li><a href="https://quarkusio.zulipchat.com">Chatroom</a></li>
          
        </ul>
      </div>
    

    
      <div class="width-3-12 more-links">
        <span>Quarkus is made of community projects</span>
        <ul class="footer-links">
          
            <li><a href="https://vertx.io/" target="_blank">Eclipse Vert.x</a></li>
          
            <li><a href="https://microprofile.io" target="_blank">Eclipse MicroProfile</a></li>
          
            <li><a href="https://hibernate.org" target="_blank">Hibernate</a></li>
          
            <li><a href="https://netty.io" target="_blank">Netty</a></li>
          
            <li><a href="https://resteasy.github.io" target="_blank">RESTEasy</a></li>
          
            <li><a href="https://camel.apache.org" target="_blank">Apache Camel</a></li>
          
            <li><a href="https://code.quarkus.io/" target="_blank">And many more...</a></li>
          
        </ul>
      </div>
    
  </div>
</div>
  <div class="content redhat-footer">
  <div class="grid-wrapper">
    <span class="licence">
      <i class="fab fa-creative-commons"></i><i class="fab fa-creative-commons-by"></i> <a href="https://creativecommons.org/licenses/by/3.0/" target="_blank">CC by 3.0</a> | <a href="https://www.redhat.com/en/about/privacy-policy">Privacy Policy</a>
    </span>
    <span class="redhat">
      Sponsored by
    </span>
    <span class="redhat-logo">
      <a href="https://www.redhat.com/" target="_blank"><img src="/assets/images/redhat_reversed.svg"></a>
    </span>
  </div>
</div>


  <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js" integrity="sha384-8gBf6Y4YYq7Jx97PIqmTwLPin4hxIzQw5aDmUg/DDhul9fFpbbLcLh3nTIIDJKhx" crossorigin="anonymous"></script>
  <script type="text/javascript" src="/assets/javascript/mobile-nav.js"></script>
  <script type="text/javascript" src="/assets/javascript/scroll-down.js"></script>
  <script src="/assets/javascript/satellite.js" type="text/javascript"></script>
  <script src="https://quarkus.io/guides/javascript/config.js" type="text/javascript"></script>
  <script src="/assets/javascript/search-filter.js" type="text/javascript"></script>
  <script src="/assets/javascript/back-to-top.js" type="text/javascript"></script>
</body>

</html>
